package com.changgou.web.gateway.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;

@Service
public class AuthService {

    @Autowired
    private StringRedisTemplate redisTemplate;

    //从Cookie中获得Jti
    public String getJtiFromCookie(ServerHttpRequest request) {
        HttpCookie uid = request.getCookies().getFirst("uid");
        if (uid!=null){
            return uid.getValue();
        }
        return null;
    }

    ////从Redis中获得Jwt
    public String getJwtFromRedis(String jti) {
        String jwt = redisTemplate.boundValueOps(jti).get();
        return jwt;
    }
}
